//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "CashFlows.h"
using namespace Cephei::QL::Cashflows;
#include <gen/QL/CashFlow.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/InterestRate.h>
using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Cashflows::CCashFlows::CCashFlows (boost::shared_ptr<QuantLib::CashFlows>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCashFlows = NULL;
#endif
	_ppCashFlows = &childNative;
    
}
Cephei::QL::Cashflows::CCashFlows::CCashFlows (QuantLib::CashFlows& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phCashFlows = NULL;
#endif
	_ppCashFlows = new boost::shared_ptr<QuantLib::CashFlows> (&childNative);
    
    _CashFlowsOwner = owner;
    
}

Cephei::QL::Cashflows::CCashFlows::CCashFlows (CCashFlows^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCashFlows = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppCashFlows = new boost::shared_ptr<QuantLib::CashFlows> (copy->GetShared());
        
    }
}
Cephei::QL::Cashflows::CCashFlows::CCashFlows (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCashFlows = NULL;
#endif
	if (!t->IsSubclassOf(CCashFlows::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Cashflows::CCashFlows::CCashFlows (QuantLib::Handle<QuantLib::CashFlows>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phCashFlows = &childNative;
	_ppCashFlows = &static_cast<boost::shared_ptr<QuantLib::CashFlows>>(childNative.currentLink());
    
    _CashFlowsOwner = owner;
}
Cephei::QL::Cashflows::CCashFlows::CCashFlows (QuantLib::Handle<QuantLib::CashFlows> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phCashFlows = &childNative;
	_ppCashFlows = &static_cast<boost::shared_ptr<QuantLib::CashFlows>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Cashflows::CCashFlows::CCashFlows (QuantLib::CashFlows childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCashFlows = NULL;
#endif
	_ppCashFlows = new boost::shared_ptr<QuantLib::CashFlows> (new QuantLib::CashFlows (childNative));
    
}
#endif

Cephei::QL::Cashflows::CCashFlows::~CCashFlows ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppCashFlows != NULL)
    {
	    delete _ppCashFlows;
        _ppCashFlows = NULL;
    }
}
Cephei::QL::Cashflows::CCashFlows::!CCashFlows ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppCashFlows != NULL)
    {
	    delete _ppCashFlows;
    }
}
QuantLib::CashFlows& Cephei::QL::Cashflows::CCashFlows::GetReference ()
{
    if (_ppCashFlows == NULL) throw REFNEW NativeNullException ();
	return **_ppCashFlows;
}
boost::shared_ptr<QuantLib::CashFlows>& Cephei::QL::Cashflows::CCashFlows::GetShared ()
{
    if (_ppCashFlows == NULL) throw REFNEW NativeNullException ();
	return *_ppCashFlows;
}
QuantLib::CashFlows* Cephei::QL::Cashflows::CCashFlows::GetPointer ()
{
    if (_ppCashFlows == NULL) throw REFNEW NativeNullException ();
	return &**_ppCashFlows;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::CashFlows>& Cephei::QL::Cashflows::CCashFlows::GetHandle ()
{
	if (_phCashFlows == NULL)
	{
		_phCashFlows = new Handle<QuantLib::CashFlows> (*_ppCashFlows);
	}
	return *_phCashFlows;
}
#endif
bool Cephei::QL::Cashflows::CCashFlows::HasNative () 
{
	return (_ppCashFlows != NULL);
}

Double Cephei::QL::Cashflows::CCashFlows::AccruedAmount (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->accruedAmount ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::AtmRate (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::Termstructures::IYieldTermStructure^ discountCurve, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate, Microsoft::FSharp::Core::FSharpOption<Double>^ npv)
{
    CYieldTermStructure^ _CdiscountCurve;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _CdiscountCurve = safe_cast<CYieldTermStructure^> (discountCurve);
        _CdiscountCurve->Lock();
        QuantLib::YieldTermStructure& _discountCurve = static_cast<QuantLib::YieldTermStructure&> (_CdiscountCurve->GetReference ()); 
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
        QuantLib::Real _npv = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (npv) ? (QuantLib::Real)ValueHelper::Convert (npv->Value) : Null<QuantLib::Real>()); //9a
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCashFlows)->atmRate ( _leg,  _discountCurve,  _includeSettlementDateFlows,  _settlementDate,  _npvDate,  _npv );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdiscountCurve != nullptr) _CdiscountCurve->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::BasisPointValue (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Double yield, Cephei::QL::Times::IDayCounter^ dayCounter, QL::CompoundingEnum compounding, QL::Times::FrequencyEnum frequency, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CDayCounter^ _CdayCounter;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        QuantLib::Rate _yield = (QuantLib::Rate)ValueHelper::Convert (yield); //a
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Compounding _compounding = (QuantLib::Compounding)compounding ;
        QuantLib::Frequency _frequency = (QuantLib::Frequency)frequency ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->basisPointValue ( _leg,  _yield,  _dayCounter,  _compounding,  _frequency,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::BasisPointValue (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::IInterestRate^ yield, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CInterestRate^ _Cyield;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _Cyield = safe_cast<CInterestRate^> (yield);
        _Cyield->Lock();
        QuantLib::InterestRate& _yield = static_cast<QuantLib::InterestRate&> (_Cyield->GetReference ()); 
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->basisPointValue ( _leg,  _yield,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_Cyield != nullptr) _Cyield->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Bps (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Double yield, Cephei::QL::Times::IDayCounter^ dayCounter, QL::CompoundingEnum compounding, QL::Times::FrequencyEnum frequency, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CDayCounter^ _CdayCounter;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        QuantLib::Rate _yield = (QuantLib::Rate)ValueHelper::Convert (yield); //a
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Compounding _compounding = (QuantLib::Compounding)compounding ;
        QuantLib::Frequency _frequency = (QuantLib::Frequency)frequency ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->bps ( _leg,  _yield,  _dayCounter,  _compounding,  _frequency,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Bps (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::IInterestRate^ yield, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CInterestRate^ _Cyield;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _Cyield = safe_cast<CInterestRate^> (yield);
        _Cyield->Lock();
        QuantLib::InterestRate& _yield = static_cast<QuantLib::InterestRate&> (_Cyield->GetReference ()); 
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->bps ( _leg,  _yield,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_Cyield != nullptr) _Cyield->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Bps (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::Termstructures::IYieldTermStructure^ discountCurve, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CYieldTermStructure^ _CdiscountCurve;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _CdiscountCurve = safe_cast<CYieldTermStructure^> (discountCurve);
        _CdiscountCurve->Lock();
        QuantLib::YieldTermStructure& _discountCurve = static_cast<QuantLib::YieldTermStructure&> (_CdiscountCurve->GetReference ()); 
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->bps ( _leg,  _discountCurve,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdiscountCurve != nullptr) _CdiscountCurve->Unlock();
    }
}
DateTime Cephei::QL::Cashflows::CCashFlows::MaturityDate (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCashFlows)->maturityDate ( _leg );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
DateTime Cephei::QL::Cashflows::CCashFlows::StartDate (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCashFlows)->startDate ( _leg );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Convexity (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Double yield, Cephei::QL::Times::IDayCounter^ dayCounter, QL::CompoundingEnum compounding, QL::Times::FrequencyEnum frequency, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CDayCounter^ _CdayCounter;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        QuantLib::Rate _yield = (QuantLib::Rate)ValueHelper::Convert (yield); //a
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Compounding _compounding = (QuantLib::Compounding)compounding ;
        QuantLib::Frequency _frequency = (QuantLib::Frequency)frequency ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->convexity ( _leg,  _yield,  _dayCounter,  _compounding,  _frequency,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Convexity (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::IInterestRate^ yield, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CInterestRate^ _Cyield;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _Cyield = safe_cast<CInterestRate^> (yield);
        _Cyield->Lock();
        QuantLib::InterestRate& _yield = static_cast<QuantLib::InterestRate&> (_Cyield->GetReference ()); 
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->convexity ( _leg,  _yield,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_Cyield != nullptr) _Cyield->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Duration (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Double yield, Cephei::QL::Times::IDayCounter^ dayCounter, QL::CompoundingEnum compounding, QL::Times::FrequencyEnum frequency, QL::Cashflows::Duration::TypeEnum type, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CDayCounter^ _CdayCounter;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        QuantLib::Rate _yield = (QuantLib::Rate)ValueHelper::Convert (yield); //a
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Compounding _compounding = (QuantLib::Compounding)compounding ;
        QuantLib::Frequency _frequency = (QuantLib::Frequency)frequency ;
        QuantLib::Duration::Type _type = (QuantLib::Duration::Type)type ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Time _rv = (QuantLib::Time)(*_ppCashFlows)->duration ( _leg,  _yield,  _dayCounter,  _compounding,  _frequency,  _type,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Duration (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::IInterestRate^ yield, QL::Cashflows::Duration::TypeEnum type, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CInterestRate^ _Cyield;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _Cyield = safe_cast<CInterestRate^> (yield);
        _Cyield->Lock();
        QuantLib::InterestRate& _yield = static_cast<QuantLib::InterestRate&> (_Cyield->GetReference ()); 
        QuantLib::Duration::Type _type = (QuantLib::Duration::Type)type ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Time _rv = (QuantLib::Time)(*_ppCashFlows)->duration ( _leg,  _yield,  _type,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_Cyield != nullptr) _Cyield->Unlock();
    }
}
Boolean Cephei::QL::Cashflows::CCashFlows::IsExpired (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	bool _rv = (bool)(*_ppCashFlows)->isExpired ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::NextCashFlowAmount (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->nextCashFlowAmount ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
DateTime Cephei::QL::Cashflows::CCashFlows::NextCashFlowDate (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCashFlows)->nextCashFlowDate ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::NextCouponRate (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCashFlows)->nextCouponRate ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Npv (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::Termstructures::IYieldTermStructure^ discount, Double zSpread, Cephei::QL::Times::IDayCounter^ dayCounter, QL::CompoundingEnum compounding, QL::Times::FrequencyEnum frequency, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CYieldTermStructure^ _Cdiscount;
    CDayCounter^ _CdayCounter;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _Cdiscount = safe_cast<CYieldTermStructure^> (discount);
        _Cdiscount->Lock();
        boost::shared_ptr<QuantLib::YieldTermStructure>& _discount = static_cast<boost::shared_ptr<QuantLib::YieldTermStructure>&> (_Cdiscount->GetShared ()); 
        QuantLib::Spread _zSpread = (QuantLib::Spread)ValueHelper::Convert (zSpread); //a
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Compounding _compounding = (QuantLib::Compounding)compounding ;
        QuantLib::Frequency _frequency = (QuantLib::Frequency)frequency ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->npv ( _leg,  _discount,  _zSpread,  _dayCounter,  _compounding,  _frequency,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_Cdiscount != nullptr) _Cdiscount->Unlock();
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Npv (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Double yield, Cephei::QL::Times::IDayCounter^ dayCounter, QL::CompoundingEnum compounding, QL::Times::FrequencyEnum frequency, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CDayCounter^ _CdayCounter;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        QuantLib::Rate _yield = (QuantLib::Rate)ValueHelper::Convert (yield); //a
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Compounding _compounding = (QuantLib::Compounding)compounding ;
        QuantLib::Frequency _frequency = (QuantLib::Frequency)frequency ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->npv ( _leg,  _yield,  _dayCounter,  _compounding,  _frequency,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Npv (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::IInterestRate^ yield, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CInterestRate^ _Cyield;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _Cyield = safe_cast<CInterestRate^> (yield);
        _Cyield->Lock();
        QuantLib::InterestRate& _yield = static_cast<QuantLib::InterestRate&> (_Cyield->GetReference ()); 
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->npv ( _leg,  _yield,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_Cyield != nullptr) _Cyield->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Npv (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::Termstructures::IYieldTermStructure^ discountCurve, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CYieldTermStructure^ _CdiscountCurve;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _CdiscountCurve = safe_cast<CYieldTermStructure^> (discountCurve);
        _CdiscountCurve->Lock();
        QuantLib::YieldTermStructure& _discountCurve = static_cast<QuantLib::YieldTermStructure&> (_CdiscountCurve->GetReference ()); 
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->npv ( _leg,  _discountCurve,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdiscountCurve != nullptr) _CdiscountCurve->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::PreviousCashFlowAmount (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->previousCashFlowAmount ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
DateTime Cephei::QL::Cashflows::CCashFlows::PreviousCashFlowDate (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCashFlows)->previousCashFlowDate ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::PreviousCouponRate (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCashFlows)->previousCouponRate ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Yield (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Double npv, Cephei::QL::Times::IDayCounter^ dayCounter, QL::CompoundingEnum compounding, QL::Times::FrequencyEnum frequency, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate, Microsoft::FSharp::Core::FSharpOption<Double>^ accuracy, Microsoft::FSharp::Core::FSharpOption<UInt64>^ maxIterations, Microsoft::FSharp::Core::FSharpOption<Double>^ guess)
{
    CDayCounter^ _CdayCounter;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        QuantLib::Real _npv = (QuantLib::Real)ValueHelper::Convert (npv); //a
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Compounding _compounding = (QuantLib::Compounding)compounding ;
        QuantLib::Frequency _frequency = (QuantLib::Frequency)frequency ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
        QuantLib::Real _accuracy = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (accuracy) ? (QuantLib::Real)ValueHelper::Convert (accuracy->Value) : 1.0e-10); //9a
        QuantLib::Size _maxIterations = 
            (Microsoft::FSharp::Core::FSharpOption<UInt64>::IsSome::get (maxIterations) ? (QuantLib::Size)ValueHelper::Convert (maxIterations->Value) : 100); //9a
        QuantLib::Rate _guess = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (guess) ? (QuantLib::Rate)ValueHelper::Convert (guess->Value) : 0.05); //9a
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCashFlows)->yield ( _leg,  _npv,  _dayCounter,  _compounding,  _frequency,  _includeSettlementDateFlows,  _settlementDate,  _npvDate,  _accuracy,  _maxIterations,  _guess );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::YieldValueBasisPoint (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Double yield, Cephei::QL::Times::IDayCounter^ dayCounter, QL::CompoundingEnum compounding, QL::Times::FrequencyEnum frequency, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CDayCounter^ _CdayCounter;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        QuantLib::Rate _yield = (QuantLib::Rate)ValueHelper::Convert (yield); //a
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Compounding _compounding = (QuantLib::Compounding)compounding ;
        QuantLib::Frequency _frequency = (QuantLib::Frequency)frequency ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->yieldValueBasisPoint ( _leg,  _yield,  _dayCounter,  _compounding,  _frequency,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::YieldValueBasisPoint (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::IInterestRate^ yield, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate)
{
    CInterestRate^ _Cyield;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _Cyield = safe_cast<CInterestRate^> (yield);
        _Cyield->Lock();
        QuantLib::InterestRate& _yield = static_cast<QuantLib::InterestRate&> (_Cyield->GetReference ()); 
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->yieldValueBasisPoint ( _leg,  _yield,  _includeSettlementDateFlows,  _settlementDate,  _npvDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_Cyield != nullptr) _Cyield->Unlock();
    }
}
Double Cephei::QL::Cashflows::CCashFlows::ZSpread (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::Termstructures::IYieldTermStructure^ d, Double npv, Cephei::QL::Times::IDayCounter^ dayCounter, QL::CompoundingEnum compounding, QL::Times::FrequencyEnum frequency, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate, Microsoft::FSharp::Core::FSharpOption<Double>^ accuracy, Microsoft::FSharp::Core::FSharpOption<UInt64>^ maxIterations, Microsoft::FSharp::Core::FSharpOption<Double>^ guess)
{
    CYieldTermStructure^ _Cd;
    CDayCounter^ _CdayCounter;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _Cd = safe_cast<CYieldTermStructure^> (d);
        _Cd->Lock();
        boost::shared_ptr<QuantLib::YieldTermStructure>& _d = static_cast<boost::shared_ptr<QuantLib::YieldTermStructure>&> (_Cd->GetShared ()); 
        QuantLib::Real _npv = (QuantLib::Real)ValueHelper::Convert (npv); //a
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Compounding _compounding = (QuantLib::Compounding)compounding ;
        QuantLib::Frequency _frequency = (QuantLib::Frequency)frequency ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
        QuantLib::Real _accuracy = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (accuracy) ? (QuantLib::Real)ValueHelper::Convert (accuracy->Value) : 1.0e-10); //9a
        QuantLib::Size _maxIterations = 
            (Microsoft::FSharp::Core::FSharpOption<UInt64>::IsSome::get (maxIterations) ? (QuantLib::Size)ValueHelper::Convert (maxIterations->Value) : 100); //9a
        QuantLib::Rate _guess = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (guess) ? (QuantLib::Rate)ValueHelper::Convert (guess->Value) : 0.0); //9a
    	QuantLib::Spread _rv = (QuantLib::Spread)(*_ppCashFlows)->zSpread ( _leg,  _d,  _npv,  _dayCounter,  _compounding,  _frequency,  _includeSettlementDateFlows,  _settlementDate,  _npvDate,  _accuracy,  _maxIterations,  _guess );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_Cd != nullptr) _Cd->Unlock();
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Int64 Cephei::QL::Cashflows::CCashFlows::AccrualDays (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::BigInteger _rv = (QuantLib::BigInteger)(*_ppCashFlows)->accrualDays ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        Int64 _nrv = (Int64)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
DateTime Cephei::QL::Cashflows::CCashFlows::AccrualEndDate (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCashFlows)->accrualEndDate ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::AccrualPeriod (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Time _rv = (QuantLib::Time)(*_ppCashFlows)->accrualPeriod ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
DateTime Cephei::QL::Cashflows::CCashFlows::AccrualStartDate (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlDate) ? (QuantLib::Date)ValueHelper::Convert (settlDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCashFlows)->accrualStartDate ( _leg,  _includeSettlementDateFlows,  _settlDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Int64 Cephei::QL::Cashflows::CCashFlows::AccruedDays (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::BigInteger _rv = (QuantLib::BigInteger)(*_ppCashFlows)->accruedDays ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        Int64 _nrv = (Int64)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::AccruedPeriod (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Time _rv = (QuantLib::Time)(*_ppCashFlows)->accruedPeriod ( _leg,  _includeSettlementDateFlows,  _settlementDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::Nominal (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlDate) ? (QuantLib::Date)ValueHelper::Convert (settlDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCashFlows)->nominal ( _leg,  _includeSettlementDateFlows,  _settlDate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Cephei::QL::Cashflows::ICashFlows^ Cephei::QL::Cashflows::CCashFlows::Npvbps (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Cephei::QL::Termstructures::IYieldTermStructure^ discountCurve, Boolean includeSettlementDateFlows, DateTime settlementDate, DateTime npvDate, Double npv, Double bps)
{
    CYieldTermStructure^ _CdiscountCurve;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        _CdiscountCurve = safe_cast<CYieldTermStructure^> (discountCurve);
        _CdiscountCurve->Lock();
        QuantLib::YieldTermStructure& _discountCurve = static_cast<QuantLib::YieldTermStructure&> (_CdiscountCurve->GetReference ()); 
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = (QuantLib::Date)ValueHelper::Convert (settlementDate); //a
        QuantLib::Date _npvDate = (QuantLib::Date)ValueHelper::Convert (npvDate); //a
        QuantLib::Real _npv = (QuantLib::Real)ValueHelper::Convert (npv); //a
        QuantLib::Real _bps = (QuantLib::Real)ValueHelper::Convert (bps); //a
    	(*_ppCashFlows)->npvbps ( _leg,  _discountCurve,  _includeSettlementDateFlows,  _settlementDate,  _npvDate,  _npv,  _bps );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_CdiscountCurve != nullptr) _CdiscountCurve->Unlock();
    }
}
DateTime Cephei::QL::Cashflows::CCashFlows::ReferencePeriodEnd (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlDate) ? (QuantLib::Date)ValueHelper::Convert (settlDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCashFlows)->referencePeriodEnd ( _leg,  _includeSettlementDateFlows,  _settlDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
DateTime Cephei::QL::Cashflows::CCashFlows::ReferencePeriodStart (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlDate) ? (QuantLib::Date)ValueHelper::Convert (settlDate->Value) : QuantLib::Date()); //9a
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCashFlows)->referencePeriodStart ( _leg,  _includeSettlementDateFlows,  _settlDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
    }
}
Double Cephei::QL::Cashflows::CCashFlows::ZSpread (Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ leg, Double npv, Cephei::QL::Termstructures::IYieldTermStructure^ prm1, Cephei::QL::Times::IDayCounter^ dayCounter, QL::CompoundingEnum compounding, QL::Times::FrequencyEnum frequency, Boolean includeSettlementDateFlows, Microsoft::FSharp::Core::FSharpOption<DateTime>^ settlementDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ npvDate, Microsoft::FSharp::Core::FSharpOption<Double>^ accuracy, Microsoft::FSharp::Core::FSharpOption<UInt64>^ maxIterations, Microsoft::FSharp::Core::FSharpOption<Double>^ guess)
{
    CYieldTermStructure^ _Cprm1;
    CDayCounter^ _CdayCounter;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        leg->Lock();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIleg = leg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCleg = safe_cast<CCashFlowVector^>(_NCIleg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _leg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCleg->GetShared ());
        QuantLib::Real _npv = (QuantLib::Real)ValueHelper::Convert (npv); //a
        _Cprm1 = safe_cast<CYieldTermStructure^> (prm1);
        _Cprm1->Lock();
        boost::shared_ptr<QuantLib::YieldTermStructure>& _prm1 = static_cast<boost::shared_ptr<QuantLib::YieldTermStructure>&> (_Cprm1->GetShared ()); 
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Compounding _compounding = (QuantLib::Compounding)compounding ;
        QuantLib::Frequency _frequency = (QuantLib::Frequency)frequency ;
        bool _includeSettlementDateFlows = (bool)ValueHelper::Convert (includeSettlementDateFlows); //a
        QuantLib::Date _settlementDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (settlementDate) ? (QuantLib::Date)ValueHelper::Convert (settlementDate->Value) : QuantLib::Date()); //9a
        QuantLib::Date _npvDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (npvDate) ? (QuantLib::Date)ValueHelper::Convert (npvDate->Value) : QuantLib::Date()); //9a
        QuantLib::Real _accuracy = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (accuracy) ? (QuantLib::Real)ValueHelper::Convert (accuracy->Value) : 1.0e-10); //9a
        QuantLib::Size _maxIterations = 
            (Microsoft::FSharp::Core::FSharpOption<UInt64>::IsSome::get (maxIterations) ? (QuantLib::Size)ValueHelper::Convert (maxIterations->Value) : 100); //9a
        QuantLib::Rate _guess = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (guess) ? (QuantLib::Rate)ValueHelper::Convert (guess->Value) : 0.0); //9a
    	QuantLib::Spread _rv = (QuantLib::Spread)(*_ppCashFlows)->zSpread ( _leg,  _npv,  _prm1,  _dayCounter,  _compounding,  _frequency,  _includeSettlementDateFlows,  _settlementDate,  _npvDate,  _accuracy,  _maxIterations,  _guess );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (leg != nullptr) leg->Unlock(); //NO2  
        if (_Cprm1 != nullptr) _Cprm1->Unlock();
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

